package com.jshoperxms.service.impl;

import com.jshoperxms.controller.utils.DateTools;
import com.jshoperxms.controller.utils.enums.BaseEnums;
import com.jshoperxms.controller.utils.statickey.TagWords;
import com.jshoperxms.dao.GoodsSpecialContentTDao;
import com.jshoperxms.dao.GoodsSpecialTDao;
import com.jshoperxms.entity.GoodsSpecialContentT;
import com.jshoperxms.entity.GoodsSpecialT;
import com.jshoperxms.service.GoodsSpecialContentTService;
import com.jshoperxms.service.GoodsSpecialTService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by sdywcd on 16/10/19.
 * Des:
 */
@Service("goodsSpecialTService")
@Scope("prototype")
public class GoodsSpecialTServiceImpl extends BaseTServiceImpl<GoodsSpecialT> implements GoodsSpecialTService {

    @Resource
    private GoodsSpecialTDao goodsSpecialTDao;

    @Resource
    private GoodsSpecialContentTDao goodsSpecialContentTDao;

    @Override
    public void saveGoodsSpecialTransactional(GoodsSpecialT goodsSpecialT, String content) {

    }

    @Override
    public void updateGoodsSpecialTransactional(GoodsSpecialT goodsSpecialT, String content) {

    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public void delGoodsSpecialTransactional(String spids) {
        String ids[]= StringUtils.split(spids, TagWords.SPLITDOT);
        for(String s:ids){
            GoodsSpecialT bean=this.goodsSpecialTDao.findByPK(GoodsSpecialT.class,s);
            if(bean!=null){
                bean.setStatus(BaseEnums.DataUsingState.DEL.getState());
                bean.setUpdatetime(DateTools.getSystemTimeBi());
                bean.setVersiont(bean.getVersiont()+1);
                this.goodsSpecialTDao.update(bean);
                Criterion criterion= Restrictions.eq("goodsSpecialTId",bean.getId());
                GoodsSpecialContentT contentT=this.goodsSpecialContentTDao.findOneByCriteria(GoodsSpecialContentT.class,criterion);
                if(contentT!=null){
                    contentT.setStatus(BaseEnums.DataUsingState.DEL.getState());
                    contentT.setUpdatetime(DateTools.getSystemTimeBi());
                    this.goodsSpecialContentTDao.update(contentT);
                }
            }
        }

    }
}
